@extends('admin_system.layout.layout')
@section('content')
    <div class="container" style="width: 100%" id="app">
        <br>
        <div class="list-group">
            <a href="#" class="list-group-item active">
                <h4 class="list-group-item-heading">Banner列表</h4>
                <p class="list-group-item-text">显示所有的banner列表</p>
            </a>
        </div>

        <div class="btn-group">
            <button type="button" class="btn btn-info">
                <a href="{{route('banner_index',['sort'=>'desc'])}}">反序</a>
            </button>
            <button type="button" class="btn btn-danger">
                <a href="{{route('banner_index',['sort'=>'asc'])}}">正序</a>
            </button>
        </div>
        <hr>

            <table class="table table-bordered table-hover">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>类型</th>
                    <th>封面标题</th>
                    <th>封面图片</th>
                    <th>视频地址</th>
                    <th>操作</th>
                </tr>
                </thead>
                @foreach($data as $k=>$v)
                <tr id="{{$v['id']}}">
                    <td>{{$v['id']}}</td>
                    <td>{{$v['banner_type']}}</td>
                    <td>{{$v['banner_title']}}</td>
                    <td style="width: 200px"><img src="{{$v['banner_img']}}" height="200px"></td>
                    <td>{{$v['has_lessons_one']['title'] or '国政课程的ID-'.$v['content_id']}}</td>
                    <td style="width: 25%">
                        <div class="btn-group">
                            <button type="button" class="btn btn-danger" onclick="delBanner(this,'{{$v['id']}}')">删除
                            </button>
                            <button type="button" class="btn btn-info">
                                <a href="{{route('banner_update_index',['id'=>$v['id'],'type'=>$v['banner_type'],'content_id'=>isset($v['has_lessons_one']['id'])?$v['has_lessons_one']['id'] :$v['content_id']])}}">修改</a>
                            </button>
                        </div>
                    </td>
                </tr>
                @endforeach
            </table>

    </div>
    <script>
        //删除
        function delBanner(_this, id) {
            $.ajax({
                url: '{{route('bannerDel')}}',
                type: 'get',
                data: {'banner_id': id},
                dataType: 'json',
                beforeSend: function () {
                    $(this).text('正在删除中...').attr('disabled', 'disabled');
                },
                success: function (data) {
                    notify_message(data.msg, 'success');
                    $(_this).parents('table').css('display', 'none');
                }
            })
        }

        //消息通知
        function notify_message(message, type) {

            $.notify({
                icon: 'fa fa-paw',
                message: message,
            }, {
                type: type,
                animate: {
                    enter: "animated fadeInDown",
                    exit: "animated fadeOutUp"
                }
            })
        }

        //切换tab
        function change_tab() {
//        window.location.reload();
            $('.nav li:nth-child(1)').addClass('active');
            $('#tab1').addClass('active in')
            $('.nav li:nth-child(2)').removeClass('active');
            $('#tab2').removeClass('active in');
        }
    </script>
@stop

